home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b124.asm < prev    next >
Assembly Source File  |  1992-04-28  |  4KB  |  72 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.24    Table Lookup with Linear Interpolation Between Points  
  8. ;This performs a table lookup and linear interpolation between points in  the table.  It is assumed that 
  9. ;the spacing between the known values  (breakpoints) is a constant.  No range checking is  per-
  10. ;formed on the input number because it is assumed that previous  calculations may have limiting and 
  11. ;range checking.  This can be used to  approximate arbitrary functions given a set of known points 
  12. ;(such as  digital sine wave generation) or to interpolate linearly between values  of a set of data such 
  13. ;as an image.  
  14. ;The function to be approximated is shown below:  
  15. ;                                 o           ? known values of function 
  16. ;                          o             o 
  17. ;   Y(i)            o 
  18. ;         
  19. ;            o 
  20. ;        ----+------+------+------+------+ 
  21. ;  X(i)?   1.0    6.0   11.0   16.0   21.0   ? indexes 
  22. ;            ^         / spacing between indexes is INDSPC, 5.0 
  23. ;                         in this example 
  24. ;              
  25. ;           FIRSTINDEX - value of the first index in the table, 1.0 
  26. ;                        in this example 
  27. ;
  28. ;Given an input value "x", the linearly interpolated value "y"  from the tabulated known values is:  
  29. ;        Y(i+1)-Y(i) 
  30. ;   y = --------------(x-X(i)) + Y(i) 
  31. ;        X(i+1)-X(i) 
  32. ;
  33. ;                                                            Program    ICycles
  34. ;                                                            Words 
  35. ;     Approximate d4=exp(d0) for 1.0 <= x <= 21.0 
  36.      page     132,60,1,1 
  37.      org     x:0 
  38. table     dc     2.7182818e+00          ;exp(1.0) 
  39.           dc     4.0342879e+02          ;exp(6.0) 
  40.           dc     5.9874141e+04          ;exp(11.0) 
  41.           dc     8.8861105e+06          ;exp(16.0) 
  42.           dc     1.3188157e+09          ;exp(21.0) 
  43.  
  44.      org     p:$50 
  45. firstindex equ    1.0         ;value of first table index 
  46. indspc     equ    5.0         ;index spacing 
  47. rindspc    equ    1.0/indspc  ;reciprocal of index spacing 
  48.  
  49.   move    #table,n0        ;point to start of table 
  50.   move    #firstindex,d6.s ;value of first index 
  51.   move    #rindspc,d7.s    ;reciprocal of index spacing 
  52.  
  53.   fsub.s  d6,d0          ;adjust input relative to index      1     1 
  54.   fmpy.s  d7,d0,d0       ;reduce range and create index       1     1 
  55.   floor   d0,d1          ;get index                           1     1 
  56.   int     d1   d1.s,d2.s ;convert index to int,copy int part  1     1 
  57.   fsub.s  d2,d0  d1.l,r0 ;x-X(i), get ptr to table            1     1 
  58.   nop                    ;clear address ALU pipe              1     1 
  59.   move    (r0)+n0        ;point to Y(i)                       1     1 
  60.   move    x:(r0)+,d4.s   ;get Y(i)                            1     1 
  61.   move    x:(r0),d5.s    ;get Y(i+1)                          1     1 
  62.   fsub.s  d4,d5          ;Y(i+1)-Y(i)                         1     1 
  63.   fmpy.s  d0,d5,d5       ; *(x-X(i))                          1     1 
  64.   fadd.s  d5,d4          ;+Y(i)                               1     1 
  65. ;                                                             ---   --- 
  66. ;                                                     Totals:  12    12 
  67.  
  68.  
  69.